using System;
using System.Linq;
using HengTong.Model;
using Microsoft.EntityFrameworkCore;
using TiaoTaoHelper.Wtm.Models;

namespace HengTong.ViewModel._Admin.SysDataPrivilegeVms;

public partial class SysDataPrivilegeVm
{
    public Guid? GroupId { get; set; } // 组ID，用于关联数据权限组

    protected override void InitVM()
    {
        if (Entity?.TargetType == DataPrivilegeTargetType.部门)
        {
            GroupId = Entity.TargetId;
        }

        if (Entity?.TargetType == DataPrivilegeTargetType.岗位)
        {
            GroupId = DC.Set<SysJobPosition>()
                .AsNoTracking()
                .Where(e => e.ID == Entity.TargetId)
                .Select(e => e.GroupId)
                .FirstOrDefault();
        }
    }
}